<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/20 0020
 * Time: 16:15
 */

namespace app\home\controller;


use app\model\model\Ad;
use app\model\model\Contact;
use app\model\model\Free_tags;
use app\model\model\Nav;
use app\model\model\Product_type;
use app\model\model\Setup;
use app\model\model\Social;
use app\model\model\User_comment;
use app\model\model\Zhichi;
use app\model\model\Seo;
use think\Request;

class Danye extends Base
{
    //实例化
    protected $_Seo;
    protected $_Ad;
    protected $_Freetags;
    protected $_Page;
    protected $_Setup;
    protected $_Social;
    protected $_Comm;
    protected $_Nav;
    protected $_Producttype;
    protected $_product;
    protected $_Video;
    protected $_News;
    protected $_Knowledge;
    public function __construct(Request $request = null){
        parent::__construct($request);
        $this->_Ad = new Ad();
        $this->_Page = new \app\model\model\Page();
        $this->_product = new \app\model\model\Product();
        $this->_Freetags = new Free_tags();
        $this->_Setup = new Setup();
        $this->_Social = new Social();
        $this->_Comm = new User_comment();
        $this->_Producttype = new Product_type();
        $this->_Seo = new Seo();
        $this->_News = new \app\model\model\News();
        $this->_Video = new \app\model\model\Video();
        $this->_Knowledge = new \app\model\model\News();
        $this->_Nav = new Nav();
    }
    public function Sitemap(){
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);
        //产品
        $ptype = $this->_Producttype->getListSelect(true);
        foreach ($ptype as $k => $v) {
            $v['uname'] = str_replace(" ","-",$v['name']);
        }
        $this->assign('type',$ptype);
        $product = $this->_product->getListSelect(['flag'=>1],true);
        foreach ($product as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
        }
        //视频
        $videolist = $this->_Video->getListSelect(['flag'=>1],true);
        foreach ($videolist as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
        }
        //博客
        $bloglist = $this->_News->getListSelect(['classify'=>2,'flag'=>1],true);
        foreach ($bloglist as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
        }

        //关于我们下导航
        $nav = $this->_Nav->getListHome(['type'=>24,'flag'=>1]);
        //bujiantedian

        //升级只是
        $uplist = $this->_Knowledge->getListSelect(['classify'=>3,'flag'=>1],true);
        foreach ($uplist as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
        }
        $list = [
            'product'=>$product,
            'video'=>$videolist,
            'blog'=>$bloglist,
            'nav'=>$nav,
            'shengji'=>$uplist
        ];
        $this->assign('list',$list);
        return $this->fetch('ditu');
    }
    public function aboutus(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>11,'flag'=>1]);
        $this->assign('banner',$banner);
        //page
        $page = $this->_Page->getOne(7);
        $this->assign('data',$page);
        //下面的介绍
        //首页Banner下面介绍信息
        $com_intro['one'] = $this->_Freetags->getOne(26);
        $com_intro['two'] = $this->_Freetags->getOne(27);
        $com_intro['three'] = $this->_Freetags->getOne(28);

        $this->assign('com_intro',$com_intro);
        //客户评论
        $comm = $this->_Comm->getListHome();
        $this->assign('comm',$comm);
        return $this->fetch();
    }
    public function ass(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>12,'flag'=>1]);
        $this->assign('banner',$banner);
        //page
        $page = $this->_Page->getOne(8);
        $this->assign('data',$page);
        return $this->fetch();
    }
    public function companyvideo(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>32,'flag'=>1]);
        $this->assign('banner',$banner);
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);
        //page
        $page = $this->_Setup->getOne(1);
        $this->assign('data',$page);
        return $this->fetch();
    }
    public function contactus(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>13,'flag'=>1]);
        $this->assign('banner',$banner);
        //page
        $page = $this->_Page->getOne(10);
        $this->assign('data',$page);
        //setup
        $setup = $this->_Setup->getOne(['id'=>1]);
        $this->assign('setup',$setup);
        //social
        $social = $this->_Social->getOne(['id'=>1]);
        $this->assign('soc',$social);
        return $this->fetch();
    }
    public function addcontactus(){
        $name = input('name')?input('name'):false;
        $tel = input('tel')?input('tel'):false;
        if(empty($name)){
            return json_echo_msg(500,'请填写姓名!');
        }
        if(empty($tel)){
            return json_echo_msg(500,'请填写手机!');
        }
        $Contact = new Contact();
        $data = [
            'name'=>input('name'),
            'com'=>input('com'),
            'email'=>input('email'),
            'tel'=>input('tel'),
            'country'=>input('country'),
            'content'=>input('content'),
            'create_time'=>time(),
             'type'=>input('type'),
        ];
        if(input('product_id')){
            $data['product_id'] = input('product_id');
        }
        $re = $Contact->add($data);
        if($re){
             $url = WEB_URL.'admin';
             $res = email_send(false,false,false,'欧锐激光--通知邮件',"<p>有一条新的用户询盘需要处理，请<a href=".$url.">登录后台</a>查看！</p><br><p>姓名:{$data['name']}</p><p>公司:{$data['com']}</p><p>邮箱:{$data['email']}</p><p>电话:{$data['tel']}</p><p>国家:{$data['country']}</p><p>留言内容:{$data['content']}</p>");
             if($res){
                return json_echo_msg(200,'提交成功!');
            }

        }
    }
    public function aaaa(){
        email_send('z289542272@163.com',false,false,'欧锐激光--通知邮件',"111111111111");
    }
    //FAQ
    public function faq(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>18,'flag'=>1]);
        $this->assign('banner',$banner);
        //自由标签里调取
        $data1 = $this->_Freetags->getListHome(['id'=>['in',[30,31,35,36,37]],'flag'=>1]);
        $data2 = $this->_Freetags->getListHome(['id'=>['in',[32,33,34,38,39,40]],'flag'=>1]);
        $this->assign('data1',$data1);
        $this->assign('data2',$data2);
        return $this->fetch();
    }
    //证明
    public function certification(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>21,'flag'=>1]);
        $this->assign('banner',$banner);
        $data = $this->_Page->getOne(11);
        $this->assign('data',$data);
        return $this->fetch('view');
    }
    //制造能力
    public function capacity(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>22,'flag'=>1]);
        $this->assign('banner',$banner);
        $data = $this->_Page->getOne(12);
        $this->assign('data',$data);
        return $this->fetch('view');
    }
    //车间
    public function Workshop(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>23,'flag'=>1]);
        $this->assign('banner',$banner);
        $data = $this->_Page->getOne(13);
        $this->assign('data',$data);
        return $this->fetch('view');
    }
    //仓库
    public function Warehouse(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>24,'flag'=>1]);
        $this->assign('banner',$banner);
        $data = $this->_Page->getOne(14);
        $this->assign('data',$data);
        return $this->fetch('view');
    }
    public function reviews(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>25,'flag'=>1]);
        $this->assign('banner',$banner);
        $data = $this->_Page->getOne(15);
        $this->assign('data',$data);
        return $this->fetch('view');
    }
    //隐私政策
    public function Policy(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>26,'flag'=>1]);
        $this->assign('banner',$banner);
        $data = $this->_Page->getOne(16);
        $this->assign('data',$data);
        return $this->fetch('view');
    }
    //法律
    public function terms(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>30,'flag'=>1]);
        $this->assign('banner',$banner);
        $data = $this->_Page->getOne(17);
        $this->assign('data',$data);
        return $this->fetch('view');
    }
    //打样
    public function makeasample(){
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>31,'flag'=>1]);
        $this->assign('banner',$banner);
        return $this->fetch('dayang');
    }
    public function addmak(){
        $name = input('name')?input('name'):false;
        $tel = input('tel')?input('tel'):false;
        if(empty($name)){
            return json_echo_msg(500,'请填写姓名!');
        }
        if(empty($tel)){
            return json_echo_msg(500,'请填写手机!');
        }
        $data = [
            'name'=>input('name'),
            'tel'=>input('tel'),
            'com'=>input('com'),
            'email'=>input('email'),
            'type'=>input('type'),
            'address'=>input('address'),
            'content'=>input('content'),
            'create_time'=>time(),
        ];
        $zhichi = new Zhichi();
        $re= $zhichi->add($data);
        if($re){
            return json_echo_msg(200,'提交成功！');
        }else{
            return json_echo_msg(300,'失败，请重新尝试');
        }
    }
    public function page404(){
        return $this->fetch('404');
    }
}